//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.XPath;
using DotNetNuke.Application;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Framework;
using DotNetNuke.Framework.Providers;
using DotNetNuke.Security;
using DotNetNuke.Services.Cache;
using DotNetNuke.Services.Installer;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Log.EventLog;
using DotNetNuke.Services.Mail;
using DotNetNuke.Services.Scheduling;
using DotNetNuke.Services.Upgrade;
using DotNetNuke.UI.Skins;
using DotNetNuke.Entities.Controllers;
namespace DotNetNuke.Modules.Admin.Host
{
	partial class HostSettings : DotNetNuke.Entities.Modules.PortalModuleBase
	{
		private void BindData()
		{
			lblProduct.Text = DotNetNukeContext.Current.Application.Description;
			lblVersion.Text = Common.Globals.FormatVersion(DotNetNukeContext.Current.Application.Version, true);
			trBeta.Visible = (DotNetNukeContext.Current.Application.Status != ReleaseMode.Stable);
			chkBetaNotice.Checked = Entities.Host.Host.DisplayBetaNotice;
			chkUpgrade.Checked = Entities.Host.Host.CheckUpgrade;
			hypUpgrade.ImageUrl = Upgrade.UpgradeIndicator(DotNetNukeContext.Current.Application.Version, Request.IsLocal, Request.IsSecureConnection);
			if (String.IsNullOrEmpty(hypUpgrade.ImageUrl))
			{
				hypUpgrade.Visible = false;
			}
			else
			{
				hypUpgrade.NavigateUrl = Upgrade.UpgradeRedirect();
			}
			lblDataProvider.Text = ProviderConfiguration.GetProviderConfiguration("data").DefaultProvider;
			lblFramework.Text = Common.Globals.NETFrameworkVersion.ToString(2);
			if (!Upgrade.IsNETFrameworkCurrent("3.5"))
			{
				DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("FrameworkDownLevel", this.LocalResourceFile), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning);
			}
			lblIdentity.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
			lblHostName.Text = Dns.GetHostName();
			lblIPAddress.Text = Dns.GetHostEntry(lblHostName.Text).AddressList[0].ToString();
			lblPermissions.Text = Framework.SecurityPolicy.Permissions;
			if (string.IsNullOrEmpty(lblPermissions.Text))
			{
				lblPermissions.Text = Localization.GetString("None", this.LocalResourceFile);
			}
			if (string.IsNullOrEmpty(Common.Globals.ApplicationPath))
			{
				lblApplicationPath.Text = "/";
			}
			else
			{
				lblApplicationPath.Text = Common.Globals.ApplicationPath;
			}
			lblApplicationMapPath.Text = Common.Globals.ApplicationMapPath;
			lblServerTime.Text = DateTime.Now.ToString();
			lblGUID.Text = DotNetNuke.Entities.Host.Host.GUID;
			DotNetNuke.Entities.Portals.PortalController objPortals = new DotNetNuke.Entities.Portals.PortalController();
			cboHostPortal.DataSource = objPortals.GetPortals();
			cboHostPortal.DataBind();
			if (Entities.Host.Host.HostPortalID > Null.NullInteger)
			{
				if (cboHostPortal.Items.FindByValue(Entities.Host.Host.HostPortalID.ToString()) != null)
				{
					cboHostPortal.Items.FindByValue(Entities.Host.Host.HostPortalID.ToString()).Selected = true;
				}
			}
			txtHostTitle.Text = DotNetNuke.Entities.Host.Host.HostTitle;
			txtHostURL.Text = DotNetNuke.Entities.Host.Host.HostURL;
			txtHostEmail.Text = DotNetNuke.Entities.Host.Host.HostEmail;
			valHostEmail.ValidationExpression = Common.Globals.glbEmailRegEx;
			UI.Skins.SkinController objSkins = new UI.Skins.SkinController();
			ctlHostSkin.SkinRoot = SkinController.RootSkin;
			ctlHostSkin.SkinSrc = Entities.Host.Host.DefaultPortalSkin;
			ctlHostContainer.SkinRoot = SkinController.RootContainer;
			ctlHostContainer.SkinSrc = Entities.Host.Host.DefaultPortalContainer;
			ctlAdminSkin.SkinRoot = SkinController.RootSkin;
			ctlAdminSkin.SkinSrc = Entities.Host.Host.DefaultAdminSkin;
			ctlAdminContainer.SkinRoot = SkinController.RootContainer;
			ctlAdminContainer.SkinSrc = Entities.Host.Host.DefaultAdminContainer;
			foreach (KeyValuePair<string, ModuleControlInfo> kvp in ModuleControlController.GetModuleControlsByModuleDefinitionID(Null.NullInteger))
			{
				if (kvp.Value.ControlType == SecurityAccessLevel.ControlPanel)
				{
					cboControlPanel.Items.Add(new ListItem(kvp.Value.ControlKey.Replace("CONTROLPANEL:", ""), kvp.Value.ControlSrc));
				}
			}
			if (string.IsNullOrEmpty(Entities.Host.Host.ControlPanel))
			{
				if (cboControlPanel.Items.FindByValue(Common.Globals.glbDefaultControlPanel) != null)
				{
					cboControlPanel.Items.FindByValue(Common.Globals.glbDefaultControlPanel).Selected = true;
				}
			}
			else
			{
				if (cboControlPanel.Items.FindByValue(Entities.Host.Host.ControlPanel) != null)
				{
					cboControlPanel.Items.FindByValue(Entities.Host.Host.ControlPanel).Selected = true;
				}
			}
			Common.Lists.ListController ctlList = new Common.Lists.ListController();
			Common.Lists.ListEntryInfoCollection colProcessor = ctlList.GetListEntryInfoCollection("Processor", "");
			cboProcessor.DataSource = colProcessor;
			cboProcessor.DataBind();
			cboProcessor.Items.Insert(0, new ListItem("<" + Services.Localization.Localization.GetString("None_Specified") + ">", ""));
			if (cboProcessor.Items.FindByText(Entities.Host.Host.PaymentProcessor) != null)
			{
				cboProcessor.Items.FindByText(Entities.Host.Host.PaymentProcessor).Selected = true;
			}
			txtUserId.Text = Entities.Host.Host.ProcessorUserId;
			txtPassword.Attributes.Add("value", Entities.Host.Host.ProcessorPassword);
			txtHostFee.Text = Entities.Host.Host.HostFee.ToString();
			Common.Lists.ListEntryInfoCollection colCurrency = ctlList.GetListEntryInfoCollection("Currency", "");
			cboHostCurrency.DataSource = colCurrency;
			cboHostCurrency.DataBind();
			if (cboHostCurrency.Items.FindByValue(Entities.Host.Host.HostCurrency) != null)
			{
				cboHostCurrency.Items.FindByValue(Entities.Host.Host.HostCurrency).Selected = true;
			}
			else
			{
				cboHostCurrency.Items.FindByValue("USD").Selected = true;
			}
			if (cboSchedulerMode.Items.FindByValue(((int)Entities.Host.Host.SchedulerMode).ToString()) != null)
			{
				cboSchedulerMode.Items.FindByValue(((int)Entities.Host.Host.SchedulerMode).ToString()).Selected = true;
			}
			else
			{
				cboSchedulerMode.Items.FindByValue("1").Selected = true;
			}
			txtHostSpace.Text = Entities.Host.Host.HostSpace.ToString();
			txtPageQuota.Text = Entities.Host.Host.PageQuota.ToString();
			txtUserQuota.Text = Entities.Host.Host.UserQuota.ToString();
			if (String.IsNullOrEmpty(Entities.Host.Host.SiteLogStorage))
			{
				optSiteLogStorage.Items.FindByValue("D").Selected = true;
			}
			else
			{
				optSiteLogStorage.Items.FindByValue(Entities.Host.Host.SiteLogStorage).Selected = true;
			}
			txtSiteLogBuffer.Text = Entities.Host.Host.SiteLogBuffer.ToString();
			txtSiteLogHistory.Text = Entities.Host.Host.SiteLogHistory.ToString();
			cboPageState.Items.FindByValue(Entities.Host.Host.PageStatePersister).Selected = true;
			BindModuleCacheProviderList();
			BindPageCacheProviderList();
			if (cboPerformance.Items.FindByValue(((int)Entities.Host.Host.PerformanceSetting).ToString()) != null)
			{
				cboPerformance.Items.FindByValue(((int)Entities.Host.Host.PerformanceSetting).ToString()).Selected = true;
			}
			else
			{
				cboPerformance.Items.FindByValue("3").Selected = true;
			}
			cboCacheability.Items.FindByValue(Entities.Host.Host.AuthenticatedCacheability).Selected = true;
			if (cboCompression.Items.FindByValue(Entities.Host.Host.HttpCompressionAlgorithm.ToString()) != null)
			{
				cboCompression.Items.FindByValue(Entities.Host.Host.HttpCompressionAlgorithm.ToString()).Selected = true;
			}
			else
			{
				cboCompression.Items.FindByValue("0").Selected = true;
			}
			chkWhitespace.Checked = Entities.Host.Host.WhitespaceFilter;
			string docTypesetting = string.Empty;
			if (DotNetNuke.Common.Globals.DataBaseVersion != null)
			{
				DotNetNuke.Entities.Host.Host.GetHostSettingsDictionary().TryGetValue("DefaultDocType", out docTypesetting);
			}
			if (!string.IsNullOrEmpty(docTypesetting))
			{
				if (cboHostDefaultDocType.Items.FindByValue(docTypesetting) != null)
				{
					cboHostDefaultDocType.Items.FindByValue(docTypesetting).Selected = true;
				}
				else
				{
					cboHostDefaultDocType.Items.FindByValue("0").Selected = true;
				}
			}
			else
			{
				cboHostDefaultDocType.Items.FindByValue("0").Selected = true;
			}
			chkRemember.Checked = Entities.Host.Host.RememberCheckbox;
			string filePath = Common.Globals.ApplicationMapPath + "\\Compression.config";
			if (File.Exists(filePath))
			{
				FileStream fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
				XPathDocument doc = new XPathDocument(fileReader);
				foreach (XPathNavigator nav in doc.CreateNavigator().Select("compression/excludedPaths/path"))
				{
					txtExcludedPaths.Text += nav.Value.ToLower() + Environment.NewLine;
				}
				txtWhitespaceFilter.Text = doc.CreateNavigator().SelectSingleNode("compression/whitespace").Value;
			}
			txtDemoPeriod.Text = Entities.Host.Host.DemoPeriod.ToString();
			chkDemoSignup.Checked = Entities.Host.Host.DemoSignup;
			chkCopyright.Checked = Entities.Host.Host.DisplayCopyright;
			chkUsersOnline.Checked = Entities.Host.Host.EnableUsersOnline;
			chkUseCustomModuleCssClass.Checked = Entities.Host.Host.EnableCustomModuleCssClass;
			txtUsersOnlineTime.Text = Entities.Host.Host.UsersOnlineTimeWindow.ToString();
			txtAutoAccountUnlock.Text = Entities.Host.Host.AutoAccountUnlockDuration.ToString();
			txtProxyServer.Text = Entities.Host.Host.ProxyServer;
			txtProxyPort.Text = Entities.Host.Host.ProxyPort.ToString();
			txtProxyUsername.Text = Entities.Host.Host.ProxyUsername;
			txtProxyPassword.Attributes.Add("value", Entities.Host.Host.ProxyPassword);
			txtWebRequestTimeout.Text = Entities.Host.Host.WebRequestTimeout.ToString();
			txtSMTPServer.Text = Entities.Host.Host.SMTPServer;
			if (!string.IsNullOrEmpty(Entities.Host.Host.SMTPAuthentication))
			{
				optSMTPAuthentication.Items.FindByValue(Entities.Host.Host.SMTPAuthentication).Selected = true;
			}
			else
			{
				optSMTPAuthentication.Items.FindByValue("0").Selected = true;
			}
			ShowHideSMTPCredentials();
			chkSMTPEnableSSL.Checked = Entities.Host.Host.EnableSMTPSSL;
			txtSMTPUsername.Text = Entities.Host.Host.SMTPUsername;
			txtSMTPPassword.Attributes.Add("value", Entities.Host.Host.SMTPPassword);
			txtFileExtensions.Text = Entities.Host.Host.FileExtensions;
			chkUseCustomErrorMessages.Checked = Entities.Host.Host.UseCustomErrorMessages;
			chkUseFriendlyUrls.Checked = Entities.Host.Host.UseFriendlyUrls;
			rowFriendlyUrls.Visible = chkUseFriendlyUrls.Checked;
			chkEnableRequestFilters.Checked = Entities.Host.Host.EnableRequestFilters;
			rowRequestFilters.Visible = chkEnableRequestFilters.Checked;
			chkLogBuffer.Checked = Entities.Host.Host.EventLogBuffer;
			txtHelpURL.Text = Entities.Host.Host.HelpURL;
			chkEnableHelp.Checked = Entities.Host.Host.EnableModuleOnLineHelp;
			chkAutoSync.Checked = Entities.Host.Host.EnableFileAutoSync;
			chkEnableContentLocalization.Checked = Entities.Host.Host.EnableContentLocalization;
			chkWebFarm.Checked = CachingProvider.Instance().IsWebFarm();
			jQueryVersion.Text = jQuery.Version;
			chkJQueryDebugVersion.Checked = jQuery.UseDebugScript;
			chkJQueryUseHosted.Checked = jQuery.UseHostedScript;
			txtJQueryHostedUrl.Text = jQuery.HostedUrl;
			ViewState["SelectedSchedulerMode"] = cboSchedulerMode.SelectedItem.Value;
			ViewState["SelectedLogBufferEnabled"] = chkLogBuffer.Checked;
			ViewState["SelectedUsersOnlineEnabled"] = chkUsersOnline.Checked;
			Framework.Providers.ProviderConfiguration objProviderConfiguration = Framework.Providers.ProviderConfiguration.GetProviderConfiguration("data");
			string strProviderPath = DotNetNuke.Data.DataProvider.Instance().GetProviderPath();
			ArrayList arrScriptFiles = new ArrayList();
			string[] arrFiles = Directory.GetFiles(strProviderPath, "*." + objProviderConfiguration.DefaultProvider);
			foreach (string strFile in arrFiles)
			{
				arrScriptFiles.Add(Path.GetFileNameWithoutExtension(strFile));
			}
			arrScriptFiles.Sort();
			cboVersion.DataSource = arrScriptFiles;
			cboVersion.DataBind();
		}
		private void BindModuleCacheProviderList()
		{
			cboModuleCacheProvider.DataSource = GetFilteredProviders(DotNetNuke.Services.ModuleCache.ModuleCachingProvider.GetProviderList(), "ModuleCachingProvider");
			cboModuleCacheProvider.DataBind();
			if (cboModuleCacheProvider.Items.Count > 0)
			{
				DotNetNuke.Services.ModuleCache.ModuleCachingProvider defaultModuleCache = DotNetNuke.ComponentModel.ComponentFactory.GetComponent<DotNetNuke.Services.ModuleCache.ModuleCachingProvider>();
				string providerKey = (from provider in DotNetNuke.Services.ModuleCache.ModuleCachingProvider.GetProviderList()
									  where provider.Value.Equals(defaultModuleCache)
									  select provider.Key).SingleOrDefault();
				if (!string.IsNullOrEmpty(Entities.Host.Host.ModuleCachingMethod))
				{
					if (cboModuleCacheProvider.Items.FindByValue(Entities.Host.Host.ModuleCachingMethod) != null)
					{
						cboModuleCacheProvider.Items.FindByValue(Entities.Host.Host.ModuleCachingMethod).Selected = true;
					}
					else
					{
						cboModuleCacheProvider.Items.FindByValue(providerKey).Selected = true;
					}
				}
				else
				{
					cboModuleCacheProvider.Items.FindByValue(providerKey).Selected = true;
				}
			}
		}
		private void BindPageCacheProviderList()
		{
			cboPageCacheProvider.DataSource = GetFilteredProviders(DotNetNuke.Services.OutputCache.OutputCachingProvider.GetProviderList(), "OutputCachingProvider");
			cboPageCacheProvider.DataBind();
			if (cboPageCacheProvider.Items.Count > 0)
			{
				DotNetNuke.Services.OutputCache.OutputCachingProvider defaultPageCache = DotNetNuke.ComponentModel.ComponentFactory.GetComponent<DotNetNuke.Services.OutputCache.OutputCachingProvider>();
				string providerKey = (from provider in DotNetNuke.Services.OutputCache.OutputCachingProvider.GetProviderList()
									  where provider.Value.Equals(defaultPageCache)
									  select provider.Key).SingleOrDefault();
				if (defaultPageCache != null)
				{
					PageCacheRow.Visible = true;
					if (!string.IsNullOrEmpty(Entities.Host.Host.PageCachingMethod))
					{
						if (cboPageCacheProvider.Items.FindByValue(Entities.Host.Host.PageCachingMethod) != null)
						{
							cboPageCacheProvider.Items.FindByValue(Entities.Host.Host.PageCachingMethod).Selected = true;
						}
						else
						{
							cboPageCacheProvider.Items.FindByValue(providerKey).Selected = true;
						}
					}
					else
					{
						cboPageCacheProvider.Items.FindByValue(providerKey).Selected = true;
					}
				}
			}
			else
			{
				PageCacheRow.Visible = false;
			}
		}
		private bool SkinChanged(string SkinRoot, int PortalId, DotNetNuke.UI.Skins.SkinType SkinType, string PostedSkinSrc)
		{
			UI.Skins.SkinController objSkins = new UI.Skins.SkinController();
			UI.Skins.SkinInfo objSkinInfo = null;
			string strSkinSrc = Null.NullString;
			if (objSkinInfo != null)
				strSkinSrc = objSkinInfo.SkinSrc;
			if (strSkinSrc == null)
				strSkinSrc = "";
			return strSkinSrc != PostedSkinSrc;
		}
		private void ShowHideSMTPCredentials()
		{
			if (optSMTPAuthentication.SelectedValue == "1")
			{
				trSMTPPassword.Visible = true;
				trSMTPUserName.Visible = true;
			}
			else
			{
				trSMTPPassword.Visible = false;
				trSMTPUserName.Visible = false;
			}
		}

		private void CheckSecurity()
		{
			// Verify that the current user has access to access this page
			if (!UserInfo.IsSuperUser)
			{
				Response.Redirect(Globals.NavigateURL("Access Denied"), true);
			}
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			chkUseFriendlyUrls.CheckedChanged += new EventHandler(chkUseFriendlyUrls_CheckedChanged);
			chkEnableRequestFilters.CheckedChanged += new EventHandler(chkEnableRequestFilters_CheckedChanged);
			cmdEmail.Click += new EventHandler(cmdEmail_Click);
			cmdProcessor.Click += new EventHandler(cmdProcessor_Click);
			cmdRestart.Click += new EventHandler(cmdRestart_Click);
			cmdUpdate.Click += new EventHandler(cmdUpdate_Click);
			cmdUpdateCompression.Click += new EventHandler(cmdUpdateCompression_Click);
			cmdUpgrade.Click += new EventHandler(cmdUpgrade_Click);
			cmdCache.Click += new EventHandler(cmdCache_Click);
			cmdUploadSkin.Click += new EventHandler(cmdUploadSkinContainer);
			cmdUploadContainer.Click += new EventHandler(cmdUploadSkinContainer);
			optSMTPAuthentication.SelectedIndexChanged += new EventHandler(optSMTPAuthentication_SelectedIndexChanged);

			try
			{
				CheckSecurity();
				if (Page.IsPostBack == false)
				{
					BindData();
				}
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void chkUseFriendlyUrls_CheckedChanged(object sender, System.EventArgs e)
		{
			rowFriendlyUrls.Visible = chkUseFriendlyUrls.Checked;
		}
		protected void chkEnableRequestFilters_CheckedChanged(object sender, System.EventArgs e)
		{
			rowRequestFilters.Visible = chkEnableRequestFilters.Checked;
		}
		private void cmdEmail_Click(object sender, System.EventArgs e)
		{
			try
			{
				if (!String.IsNullOrEmpty(txtHostEmail.Text))
				{
					txtSMTPPassword.Attributes.Add("value", Entities.Host.Host.SMTPPassword);
					string strMessage = Mail.SendMail(txtHostEmail.Text, txtHostEmail.Text, "", "", MailPriority.Normal, Services.Localization.Localization.GetSystemMessage(PortalSettings, "EMAIL_SMTP_TEST_SUBJECT"), MailFormat.Text, System.Text.Encoding.UTF8, "", "",
					txtSMTPServer.Text, optSMTPAuthentication.SelectedItem.Value, txtSMTPUsername.Text, txtSMTPPassword.Text, chkSMTPEnableSSL.Checked);
					if (!String.IsNullOrEmpty(strMessage))
					{
						lblEmail.Text = "<br>" + string.Format(Services.Localization.Localization.GetString("EmailErrorMessage", this.LocalResourceFile), strMessage);
						lblEmail.CssClass = "NormalRed";
					}
					else
					{
						lblEmail.Text = "<br>" + Services.Localization.Localization.GetString("EmailSentMessage", this.LocalResourceFile);
						lblEmail.CssClass = "NormalBold";
					}
				}
				else
				{
					lblEmail.Text = "<br>" + Services.Localization.Localization.GetString("SpecifyHostEmailMessage", this.LocalResourceFile);
					lblEmail.CssClass = "NormalRed";
				}
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		private void cmdProcessor_Click(object sender, System.EventArgs e)
		{
			try
			{
				Response.Redirect(Common.Globals.AddHTTP(cboProcessor.SelectedItem.Value), true);
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		private void cmdCache_Click(object sender, System.EventArgs e)
		{
			DataCache.ClearCache();
			Response.Redirect(Request.RawUrl, true);
		}
		private void cmdUpdate_Click(object sender, EventArgs e)
		{
			if (Page.IsValid)
			{
				try
				{
					CheckSecurity();
					HostController.Instance.Update("CheckUpgrade", chkUpgrade.Checked ? "Y" : "N", false);
					HostController.Instance.Update("DisplayBetaNotice", chkBetaNotice.Checked ? "Y" : "N", false);
					HostController.Instance.Update("HostPortalId", cboHostPortal.SelectedItem.Value);
					HostController.Instance.Update("HostTitle", txtHostTitle.Text, false);
					HostController.Instance.Update("HostURL", txtHostURL.Text, false);
					HostController.Instance.Update("HostEmail", txtHostEmail.Text, false);
					HostController.Instance.Update("PaymentProcessor", cboProcessor.SelectedItem.Text, false);
					HostController.Instance.Update("ProcessorUserId", txtUserId.Text, false);
					HostController.Instance.Update("ProcessorPassword", txtPassword.Text, false);
					HostController.Instance.Update("HostFee", txtHostFee.Text, false);
					HostController.Instance.Update("HostCurrency", cboHostCurrency.SelectedItem.Value, false);
					HostController.Instance.Update("HostSpace", txtHostSpace.Text, false);
					HostController.Instance.Update("PageQuota", txtPageQuota.Text, false);
					HostController.Instance.Update("UserQuota", txtUserQuota.Text, false);
					HostController.Instance.Update("SiteLogStorage", optSiteLogStorage.SelectedItem.Value, false);
					HostController.Instance.Update("SiteLogBuffer", txtSiteLogBuffer.Text, false);
					HostController.Instance.Update("SiteLogHistory", txtSiteLogHistory.Text, false);
					HostController.Instance.Update("DemoPeriod", txtDemoPeriod.Text, false);
					HostController.Instance.Update("DemoSignup", chkDemoSignup.Checked ? "Y" : "N", false);
					HostController.Instance.Update("Copyright", chkCopyright.Checked ? "Y" : "N", false);
					HostController.Instance.Update("DefaultDocType", cboHostDefaultDocType.SelectedItem.Value, false);
					HostController.Instance.Update("RememberCheckbox", chkRemember.Checked ? "Y" : "N", false);
					HostController.Instance.Update("EnableCustomModuleCssClass", chkUseCustomModuleCssClass.Checked ? "Y" : "N", false);

					bool OriginalUsersOnline;
					OriginalUsersOnline = Convert.ToBoolean(ViewState["SelectedUsersOnlineEnabled"]);
					if (OriginalUsersOnline != chkUsersOnline.Checked)
					{
						Services.Scheduling.ScheduleItem objScheduleItem;
						objScheduleItem = Services.Scheduling.SchedulingProvider.Instance().GetSchedule("DotNetNuke.Entities.Users.PurgeUsersOnline, DOTNETNUKE", Null.NullString);
						if (objScheduleItem != null)
						{
							if (chkUsersOnline.Checked)
							{
								if (!objScheduleItem.Enabled)
								{
									objScheduleItem.Enabled = true;
									Services.Scheduling.SchedulingProvider.Instance().UpdateSchedule(objScheduleItem);
									if ((SchedulerMode)Enum.Parse(typeof(SchedulerMode), cboSchedulerMode.SelectedItem.Value) == Services.Scheduling.SchedulerMode.TIMER_METHOD)
									{
										Services.Scheduling.SchedulingProvider.Instance().ReStart("Host Settings");
									}
								}
							}
							else
							{
								if (objScheduleItem.Enabled)
								{
									objScheduleItem.Enabled = false;
									Services.Scheduling.SchedulingProvider.Instance().UpdateSchedule(objScheduleItem);
									if ((SchedulerMode)Enum.Parse(typeof(SchedulerMode), cboSchedulerMode.SelectedItem.Value) == Services.Scheduling.SchedulerMode.TIMER_METHOD)
									{
										Services.Scheduling.SchedulingProvider.Instance().ReStart("Host Settings");
									}
								}
							}
						}
					}
					HostController.Instance.Update("DisableUsersOnline", chkUsersOnline.Checked ? "N" : "Y", false);
					HostController.Instance.Update("AutoAccountUnlockDuration", txtAutoAccountUnlock.Text, false);
					HostController.Instance.Update("UsersOnlineTime", txtUsersOnlineTime.Text, false);
					HostController.Instance.Update("ProxyServer", txtProxyServer.Text, false);
					HostController.Instance.Update("ProxyPort", txtProxyPort.Text, false);
					HostController.Instance.Update("ProxyUsername", txtProxyUsername.Text, false);
					HostController.Instance.Update("ProxyPassword", txtProxyPassword.Text, false);
					HostController.Instance.Update("WebRequestTimeout", txtWebRequestTimeout.Text, false);
					HostController.Instance.Update("SMTPServer", txtSMTPServer.Text, false);
					HostController.Instance.Update("SMTPAuthentication", optSMTPAuthentication.SelectedItem.Value, false);
					HostController.Instance.Update("SMTPUsername", txtSMTPUsername.Text, false);
					HostController.Instance.Update("SMTPPassword", txtSMTPPassword.Text, false);
					HostController.Instance.Update("SMTPEnableSSL", chkSMTPEnableSSL.Checked ? "Y" : "N", false);
					HostController.Instance.Update("FileExtensions", txtFileExtensions.Text, false);
					HostController.Instance.Update("UseCustomErrorMessages", chkUseCustomErrorMessages.Checked ? "Y" : "N", false);
					HostController.Instance.Update("UseFriendlyUrls", chkUseFriendlyUrls.Checked ? "Y" : "N", false);
					HostController.Instance.Update("EnableRequestFilters", chkEnableRequestFilters.Checked ? "Y" : "N", false);
					HostController.Instance.Update("ControlPanel", cboControlPanel.SelectedItem.Value, false);
					HostController.Instance.Update("SchedulerMode", cboSchedulerMode.SelectedItem.Value, false);
					HostController.Instance.Update("PerformanceSetting", cboPerformance.SelectedItem.Value, false);
					HostController.Instance.Update("AuthenticatedCacheability", cboCacheability.SelectedItem.Value, false);
					HostController.Instance.Update("PageStatePersister", cboPageState.SelectedItem.Value);
					HostController.Instance.Update("ModuleCaching", cboModuleCacheProvider.SelectedItem.Value, false);
					if (PageCacheRow.Visible)
					{
						HostController.Instance.Update("PageCaching", cboPageCacheProvider.SelectedItem.Value, false);
					}
					HostController.Instance.Update("HttpCompression", cboCompression.SelectedItem.Value, false);
					HostController.Instance.Update("WhitespaceFilter", chkWhitespace.Checked ? "Y" : "N", false);
					HostController.Instance.Update("EnableModuleOnLineHelp", chkEnableHelp.Checked ? "Y" : "N", false);
					HostController.Instance.Update("EnableFileAutoSync", chkAutoSync.Checked ? "Y" : "N", false);
					HostController.Instance.Update("HelpURL", txtHelpURL.Text, false);
					HostController.Instance.Update("EnableContentLocalization", chkEnableContentLocalization.Checked ? "Y" : "N", false);
					bool OriginalLogBuffer;
					OriginalLogBuffer = Convert.ToBoolean(ViewState["SelectedLogBufferEnabled"]);
					if (OriginalLogBuffer != chkLogBuffer.Checked)
					{
						Services.Scheduling.ScheduleItem objScheduleItem;
						objScheduleItem = Services.Scheduling.SchedulingProvider.Instance().GetSchedule("DotNetNuke.Services.Log.EventLog.PurgeLogBuffer, DOTNETNUKE", Null.NullString);
						if (objScheduleItem != null)
						{
							if (chkLogBuffer.Checked)
							{
								if (!objScheduleItem.Enabled)
								{
									objScheduleItem.Enabled = true;
									Services.Scheduling.SchedulingProvider.Instance().UpdateSchedule(objScheduleItem);
									if ((SchedulerMode)Enum.Parse(typeof(SchedulerMode), cboSchedulerMode.SelectedItem.Value) == Services.Scheduling.SchedulerMode.TIMER_METHOD)
									{
										Services.Scheduling.SchedulingProvider.Instance().ReStart("Host Settings");
									}
								}
							}
							else
							{
								if (objScheduleItem.Enabled)
								{
									objScheduleItem.Enabled = false;
									Services.Scheduling.SchedulingProvider.Instance().UpdateSchedule(objScheduleItem);
									if ((SchedulerMode)Enum.Parse(typeof(SchedulerMode), cboSchedulerMode.SelectedItem.Value) == Services.Scheduling.SchedulerMode.TIMER_METHOD)
									{
										Services.Scheduling.SchedulingProvider.Instance().ReStart("Host Settings");
									}
								}
							}
						}
					}
					HostController.Instance.Update("EventLogBuffer", chkLogBuffer.Checked ? "Y" : "N", false);
					HostController.Instance.Update("DefaultPortalSkin", ctlHostSkin.SkinSrc, false);
					HostController.Instance.Update("DefaultAdminSkin", ctlAdminSkin.SkinSrc, false);
					HostController.Instance.Update("DefaultPortalContainer", ctlHostContainer.SkinSrc, false);
					HostController.Instance.Update("DefaultAdminContainer", ctlAdminContainer.SkinSrc, false);
					HostController.Instance.Update("jQueryDebug", chkJQueryDebugVersion.Checked ? "Y" : "N", false);
					HostController.Instance.Update("jQueryHosted", chkJQueryUseHosted.Checked ? "Y" : "N", false);
					HostController.Instance.Update("jQueryUrl", txtJQueryHostedUrl.Text, false);
					Services.Scheduling.SchedulerMode OriginalSchedulerMode;
					OriginalSchedulerMode = (Services.Scheduling.SchedulerMode)Convert.ToInt32(ViewState["SelectedSchedulerMode"]);
					if ((SchedulerMode)Enum.Parse(typeof(SchedulerMode), cboSchedulerMode.SelectedItem.Value) == Services.Scheduling.SchedulerMode.DISABLED)
					{
						if (OriginalSchedulerMode != Services.Scheduling.SchedulerMode.DISABLED)
						{
							Services.Scheduling.SchedulingProvider.Instance().Halt("Host Settings");
						}
					}
					else if ((SchedulerMode)Enum.Parse(typeof(SchedulerMode), cboSchedulerMode.SelectedItem.Value) == Services.Scheduling.SchedulerMode.TIMER_METHOD)
					{
						if (OriginalSchedulerMode == Services.Scheduling.SchedulerMode.DISABLED || OriginalSchedulerMode == Services.Scheduling.SchedulerMode.REQUEST_METHOD)
						{
							Thread newThread = new Thread(Services.Scheduling.SchedulingProvider.Instance().Start);
							newThread.IsBackground = true;
							newThread.Start();
						}
					}
					else if ((SchedulerMode)Enum.Parse(typeof(SchedulerMode), cboSchedulerMode.SelectedItem.Value) != Services.Scheduling.SchedulerMode.TIMER_METHOD)
					{
						if (OriginalSchedulerMode == Services.Scheduling.SchedulerMode.TIMER_METHOD)
						{
							Services.Scheduling.SchedulingProvider.Instance().Halt("Host Settings");
						}
					}
					Response.Redirect(Request.RawUrl, true);
				}
				catch (Exception exc)
				{
					Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
				}
				finally
				{
					DataCache.ClearHostCache(false);
				}
			}
		}
		private void cmdUpgrade_Click(object sender, System.EventArgs e)
		{
			try
			{
				string strProviderPath = DotNetNuke.Data.DataProvider.Instance().GetProviderPath();
				if (File.Exists(strProviderPath + cboVersion.SelectedItem.Text + ".log.resources"))
				{
					StreamReader objStreamReader;
					objStreamReader = File.OpenText(strProviderPath + cboVersion.SelectedItem.Text + ".log.resources");
					string upgradeText = objStreamReader.ReadToEnd();
					if (String.IsNullOrEmpty(upgradeText.Trim()))
					{
						upgradeText = Localization.GetString("LogEmpty", this.LocalResourceFile);
					}
					lblUpgrade.Text = upgradeText.Replace("\n", "<br>");
					objStreamReader.Close();
				}
				else
				{
					lblUpgrade.Text = Localization.GetString("NoLog", this.LocalResourceFile);
				}
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void cmdUploadSkinContainer(object sender, System.EventArgs e)
		{
			Response.Redirect(Util.InstallURL(ModuleContext.TabId, ""), true);
		}
		private void cmdRestart_Click(object sender, System.EventArgs e)
		{
			EventLogController objEv = new EventLogController();
			LogInfo objEventLogInfo = new LogInfo();
			objEventLogInfo.BypassBuffering = true;
			objEventLogInfo.LogTypeKey = Services.Log.EventLog.EventLogController.EventLogType.HOST_ALERT.ToString();
			objEventLogInfo.AddProperty("Message", Localization.GetString("UserRestart", this.LocalResourceFile));
			objEv.AddLog(objEventLogInfo);
			Config.Touch();
			Response.Redirect(Common.Globals.NavigateURL(), true);
		}
		protected void cmdUpdateCompression_Click(object sender, System.EventArgs e)
		{
			XmlDocument xmlCompression = new XmlDocument();
			XmlNode nodeRoot = xmlCompression.CreateElement("compression");
			XmlNode nodeExcludedPaths = xmlCompression.CreateElement("excludedPaths");
			nodeRoot.AppendChild(nodeExcludedPaths);
			foreach (string strItem in txtExcludedPaths.Text.Split('\r', '\n'))
			{
				if (!String.IsNullOrEmpty(strItem.Trim()))
				{
					XmlUtils.AppendElement(ref xmlCompression, nodeExcludedPaths, "path", strItem.Trim(), false);
				}
			}
			XmlUtils.AppendElement(ref xmlCompression, nodeRoot, "whitespace", txtWhitespaceFilter.Text, false, true);
			xmlCompression.AppendChild(nodeRoot);
			XmlDeclaration xmlDeclaration;
			xmlDeclaration = xmlCompression.CreateXmlDeclaration("1.0", "utf-8", null);
			xmlCompression.InsertBefore(xmlDeclaration, nodeRoot);
			string strFile = Common.Globals.ApplicationMapPath + "\\Compression.config";
			File.SetAttributes(strFile, FileAttributes.Normal);
			xmlCompression.Save(strFile);
		}
		protected void optSMTPAuthentication_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			ShowHideSMTPCredentials();
			lblEmail.Text = "";
		}
		private IEnumerable GetFilteredProviders<T>(Dictionary<string, T> providerList, string keyFilter)
		{
			var providers = from provider in providerList
							let filteredkey = provider.Key.Replace(keyFilter, String.Empty)
							select new
							{
								filteredkey,
								provider.Key
							};

			return providers;
		}
	}
}
